﻿namespace YDT_OrderService.Domains.Entities
{
    public class OrderItem : Entity
    {
        public string OrderSn { get; private set; }
        public Guid ProductId { get; private set; }
        public string ProductUrl { get; private set; }
        public string ProductName { get; private set; }
        public decimal ItemPrice { get; private set; }
        public int ItemCount { get; private set; }
        public decimal ItemTotalPrice { get; private set; }

        protected OrderItem() { }

        public OrderItem(string orderSn, Guid productId, string productName,
                        string productUrl, decimal itemPrice, int itemCount)
        {
            Id = Guid.NewGuid();
            OrderSn = orderSn;
            ProductId = productId;
            ProductName = productName;
            ProductUrl = productUrl;
            ItemPrice = itemPrice;
            ItemCount = itemCount;
            ItemTotalPrice = itemPrice * itemCount;
        }

        public void UpdateQuantity(int newQuantity)
        {
            if (newQuantity <= 0)
                throw new ArgumentException("Quantity must be greater than 0");

            ItemCount = newQuantity;
            ItemTotalPrice = ItemPrice * ItemCount;
        }
    }
}
